{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Generate qlibrary component images\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "By running this notebook the qlibrary component image files will be update.  After the docs build is rerun the images in the docs will be updated automatically.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Start gui"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%load_ext autoreload\n",
    "%autoreload 2\n",
    "\n",
    "import qiskit_metal as metal\n",
    "from qiskit_metal import designs, draw\n",
    "from qiskit_metal import MetalGUI, Dict\n",
    "\n",
    "design = designs.DesignPlanar()\n",
    "gui = MetalGUI(design)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Qlibrary component imports and define worker function"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "from qiskit_metal.qlibrary.sample_shapes.circle_caterpillar import CircleCaterpillar\n",
    "from qiskit_metal.qlibrary.sample_shapes.circle_raster import CircleRaster\n",
    "from qiskit_metal.qlibrary.sample_shapes.n_gon import NGon\n",
    "from qiskit_metal.qlibrary.sample_shapes.n_square_spiral import NSquareSpiral\n",
    "from qiskit_metal.qlibrary.sample_shapes.rectangle import Rectangle\n",
    "from qiskit_metal.qlibrary.sample_shapes.rectangle_hollow import RectangleHollow\n",
    "\n",
    "from qiskit_metal.qlibrary.lumped.cap_3_interdigital import Cap3Interdigital\n",
    "from qiskit_metal.qlibrary.lumped.cap_n_interdigital import CapNInterdigital\n",
    "from qiskit_metal.qlibrary.lumped.resonator_coil_rect import ResonatorCoilRect\n",
    "\n",
    "from qiskit_metal.qlibrary.couplers.coupled_line_tee import CoupledLineTee\n",
    "from qiskit_metal.qlibrary.couplers.line_tee import LineTee\n",
    "from qiskit_metal.qlibrary.couplers.cap_n_interdigital_tee import CapNInterdigitalTee\n",
    "from qiskit_metal.qlibrary.couplers.tunable_coupler_01 import TunableCoupler01\n",
    "\n",
    "from qiskit_metal.qlibrary.terminations.launchpad_wb import LaunchpadWirebond\n",
    "from qiskit_metal.qlibrary.terminations.launchpad_wb_coupled import LaunchpadWirebondCoupled\n",
    "from qiskit_metal.qlibrary.terminations.open_to_ground import OpenToGround\n",
    "\n",
    "from qiskit_metal.qlibrary.qubits.JJ_Dolan import jj_dolan\n",
    "from qiskit_metal.qlibrary.qubits.JJ_Manhattan import jj_manhattan\n",
    "from qiskit_metal.qlibrary.qubits.transmon_concentric import TransmonConcentric\n",
    "from qiskit_metal.qlibrary.qubits.transmon_cross import TransmonCross\n",
    "from qiskit_metal.qlibrary.qubits.transmon_cross_fl import TransmonCrossFL\n",
    "from qiskit_metal.qlibrary.qubits.Transmon_Interdigitated import TransmonInterdigitated\n",
    "from qiskit_metal.qlibrary.qubits.transmon_pocket import TransmonPocket\n",
    "from qiskit_metal.qlibrary.qubits.transmon_pocket_cl import TransmonPocketCL\n",
    "from qiskit_metal.qlibrary.qubits.transmon_pocket_6 import TransmonPocket6\n",
    "from qiskit_metal.qlibrary.qubits.transmon_pocket_teeth import TransmonPocketTeeth\n",
    "from qiskit_metal.qlibrary.qubits.SQUID_loop import SQUID_LOOP\n",
    "from qiskit_metal.qlibrary.qubits.star_qubit import StarQubit\n",
    "\n",
    "import shutil, os"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def create_image(component, component_name, file_name):\n",
    "    obj = component(design, component_name)\n",
    "    \n",
    "    gui.rebuild()\n",
    "    gui.autoscale()\n",
    "    gui.zoom_on_components([component_name]) \n",
    "\n",
    "    gui.figure.savefig(file_name, dpi=30)\n",
    "\n",
    "    from IPython.display import Image, display\n",
    "    _disp_ops = dict(width=500)\n",
    "    display(Image(file_name, **_disp_ops))\n",
    "\n",
    "    design.delete_component(component_name)\n",
    "\n",
    "    shutil.copy(file_name, '../apidocs/')\n",
    "    os.remove(file_name)\n",
    "                "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### sample_shapes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "create_image(CircleCaterpillar, 'circlecaterpillar', 'CircleCaterpillar.png')\n",
    "create_image(CircleRaster, 'circleraster', 'CircleRaster.png')\n",
    "create_image(NGon, 'ngon', 'NGon.png')\n",
    "create_image(NSquareSpiral, 'nsquarespiral', 'NSquareSpiral.png')\n",
    "create_image(Rectangle, 'rectangle', 'Rectangle.png')\n",
    "create_image(RectangleHollow, 'rectanglehollow', 'RectangleHollow.png')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### lumped"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "create_image(Cap3Interdigital, 'cap3interdigital', 'Cap3Interdigital.png')\n",
    "create_image(CapNInterdigital, 'capninterdigital', 'CapNInterdigital.png')\n",
    "create_image(ResonatorCoilRect, 'resonatorcoilrect', 'ResonatorCoilRect.png')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### couplers"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "create_image(CoupledLineTee, 'coupledlintee', 'CoupledLineTee.png')\n",
    "create_image(LineTee, 'linetee', 'LineTee.png')\n",
    "create_image(CapNInterdigitalTee, 'capninterdigitaltee', 'CapNInterdigitalTee.png')\n",
    "create_image(TunableCoupler01, 'tunablecoupler01', 'TunableCoupler01.png')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### terminations"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "create_image(LaunchpadWirebond, 'launchpadwirebond', 'LaunchpadWirebond.png')\n",
    "create_image(LaunchpadWirebondCoupled, 'launchpadwirebondcoupled', 'LaunchpadWirebondCoupled.png')\n",
    "create_image(OpenToGround, 'opentoground', 'OpenToGround.png')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### qubits"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "create_image(jj_dolan, 'jj_dolan', 'JJDolan.png')\n",
    "create_image(jj_manhattan, 'jj_manhattan', 'JJManhattan.png')\n",
    "create_image(TransmonConcentric, 'transmonconcentric', 'TransmonConcentric.png')\n",
    "create_image(TransmonCross, 'transmoncross', 'TransmonCross.png')\n",
    "create_image(TransmonCrossFL, 'transmoncrossfl', 'TransmonCrossFL.png')\n",
    "create_image(TransmonInterdigitated, 'transmoninterdigitated', 'TransmonInterdigitated.png')\n",
    "create_image(TransmonPocket, 'transmonpocket', 'TransmonPocket.png')\n",
    "create_image(TransmonPocketCL, 'transmonpocketcl', 'TransmonPocketCL.png')\n",
    "create_image(TransmonPocket6, 'transmonpocket6', 'TransmonPocket6.png')\n",
    "create_image(TransmonPocketTeeth, 'transmonpocketteeth', 'Transmon_Pocket_Teeth.png')\n",
    "create_image(SQUID_LOOP, 'squidloop', 'SQUID_LOOP.png')\n",
    "create_image(StarQubit, 'starqubit', 'StarQubit.png')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "tags": []
   },
   "source": [
    "### Closing the Qiskit Metal GUI"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "gui.main_window.close()"
   ]
  }
 ],
 "metadata": {
  "celltoolbar": "Tags",
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
